<?PHP
$link = mysql_connect("localhost","root","");
mysql_query ("set character_set_client='utf8'"); 
mysql_query ("set character_set_results='utf8'"); 
mysql_query ("set collation_connection='utf8_general_ci'"); 
$db = mysql_select_db("gamedb");
if (!$db)
{
   echo ("Khong Load Duoc");
}
else
{
$ID=$_POST['ID'];

///////////CREATENEW/////////////////////////////////////////////////////////////////////////////////////////////
if($ID=="CREATE_NEW")
{
	$query = "INSERT INTO  canon (
	`ID` ,
	`Mindamage` ,
	`Maxdamage` ,
	`Mindamage1` ,
	`Maxdamage1` ,
	`Mindamage2` ,
	`Maxdamage2` ,
	`RangeColli` ,
	`PercentCoin` ,
	`User`
	)
	VALUES (
	NULL ,  '10',  '15',  '15',  '30',  '30',  '60',  '1.55',  '100',  '$_POST[User]'
	);";
	$results = mysql_query($query);

	$query = "INSERT INTO  solider (
	`ID` ,
	`HP` ,
	`HP1` ,
	`HP2` ,
	`Armor` ,
	`Armor1` ,
	`Armor2` ,
	`Cooldown` ,
	`Cooldown1` ,
	`RangeColli` ,
	`User`
	)
	VALUES (
	NULL ,  '50',  '100',  '150',  '0',  '1',  '1',  '10',  '11',  '1.6',  '$_POST[User]'
	);";
	$results = mysql_query($query);


	$query = "INSERT INTO  stage (
	`STT` ,
	`User` ,
	`Stage`
	)
	VALUES (
	NULL ,  '$_POST[User]',  '1'
	);
	";
	$results = mysql_query($query);


	$query = "INSERT INTO  starstage1 (
	`STT` ,
	`User` ,
	`MaxLevel` ,
	`Level1` ,
	`Level2` ,
	`Level3` ,
	`Level4` ,
	`Level5` ,
	`Level6` ,
	`Level7` ,
	`Level8` ,
	`Level9` ,
	`Level10` ,
	`Level11` ,
	`Level12`
	)
	VALUES (
	NULL ,  '$_POST[User]',  '0',  '0',  '0',  '0',  '0',  '0',  '0',  '0',  '0',  '0',  '0',  '0',  '0'
	);";
	$results = mysql_query($query);


	$query = "INSERT INTO  starstage2 (
	`STT` ,
	`User` ,
	`MaxLevel` ,
	`Level1` ,
	`Level2` ,
	`Level3` ,
	`Level4` ,
	`Level5` ,
	`Level6` ,
	`Level7` ,
	`Level8` ,
	`Level9` ,
	`Level10`
	)
	VALUES (
	NULL ,  '$_POST[User]',  '0',  '0',  '0',  '0',  '0',  '0',  '0',  '0',  '0',  '0',  '0'
	);";
	$results = mysql_query($query);

	$query = "INSERT INTO  tower (
	`ID` ,
	`Deso` ,
	`Range` ,
	`Coint` ,
	`DoubleDamage` ,
	`PercentSell` ,
	`RangeColli` ,
	`User`
	)
	VALUES (
	NULL ,  '0',  '0',  '0',  '0',  '0',  '1.5',  '$_POST[User]'
	);";
	$results = mysql_query($query);

	$query = "INSERT INTO  updatestarlevel (
	`ID` ,
	`Skill1` ,
	`Skill2` ,
	`Skill3` ,
	`Skill4` ,
	`Skill5` ,
	`Skill6` ,
	`TotalStar` ,
	`User`
	)
	VALUES (
	NULL ,  '0',  '0',  '0',  '0',  '0',  '0',  '0',  '$_POST[User]'
	);";
	$results = mysql_query($query);

}
/////////////////////////////////////////GET DATA//////////////////////////////////////////////////////////
//////////GET STAGE//////////
if($ID=="GET_STAGE")
{
	$query = "SELECT * FROM stage WHERE User='$_POST[User]'";
	$results = mysql_query($query)or die(mysql_error());

	$user = "";
	$stage = "";
	$question = "";
	while($line = mysql_fetch_assoc($results)) {
		 $user .=$line["User"]."\n";
		 $stage .=$line["Stage"]."\n";
		 $question .=$line["Question"]."\n";


	}

	echo($user);
	echo($stage);
	echo($question);
}

//////////GET CANON//////////
if($ID=="GET_CANON")
{
	$query = "SELECT * FROM canon WHERE User='$_POST[User]'";
	$results = mysql_query($query)or die(mysql_error());

	$dataMindamage = "";
	$dataMaxdamage = "";
	$dataMindamage1 = "";
	$dataMaxdamage1 = "";
	$dataMindamage2 = "";
	$dataMaxdamage2 = "";
	$dataRange = "";
	$PercentCoin = "";


	while($line = mysql_fetch_assoc($results)) {
		 $dataMindamage .= $line["Mindamage"]."\n";
		 $dataMaxdamage .= $line["Maxdamage"]."\n";
		 $dataMindamage1 .= $line["Mindamage1"]."\n";
		 $dataMaxdamage1 .= $line["Maxdamage1"]."\n";
		 $dataMindamage2 .= $line["Mindamage2"]."\n";
		 $dataMaxdamage2 .= $line["Maxdamage2"]."\n";
	 	$dataRange .= $line["RangeColli"]."\n";
	 	$PercentCoin .= $line["PercentCoin"]."\n";


	}
	echo ($dataMindamage);
	echo ($dataMaxdamage);
	echo ($dataMindamage1);
	echo ($dataMaxdamage1);
	echo ($dataMindamage2);
	echo ($dataMaxdamage2);
	echo ($dataRange);
	echo ($PercentCoin);
}

//////////GET BATRACK//////////
if($ID=="GET_BATRACK")
{
	$query = "SELECT * FROM solider WHERE User='$_POST[User]'";
	$results = mysql_query($query)or die(mysql_error());

	$dataHP = "";
	$dataHP1 = "";
	$dataHP2 = "";
	$dataArmor = "";
	$dataArmor1 = "";
	$dataArmor2 = "";
	$dataCooldown = "";
	$dataCooldown1 = "";
	$dataRange = "";

	while($line = mysql_fetch_assoc($results)) {
		 $dataHP .= $line["HP"]."\n";
		 $dataHP1 .= $line["HP1"]."\n";
		 $dataHP2 .= $line["HP2"]."\n";
		 $dataArmor .= $line["Armor"]."\n";
		 $dataArmor1 .= $line["Armor1"]."\n";
		 $dataArmor2 .= $line["Armor2"]."\n";
		 $dataCooldown .= $line["Cooldown"]."\n";
		 $dataCooldown1 .= $line["Cooldown1"]."\n";
		 $dataRange .=$line["RangeColli"]."\n";

	}
	echo($dataHP);
	echo($dataHP1);
	echo($dataHP2);
	echo($dataArmor);
	echo($dataArmor1);
	echo($dataArmor2);
	echo($dataCooldown);
	echo($dataCooldown1);
	echo($dataRange);
}

//////////GET STARSTAGE1//////////
if($ID=="GET_STARSTAGE1")
{
	$query = "SELECT * FROM starstage1 WHERE User='$_POST[User]'";
	$results = mysql_query($query)or die(mysql_error());

	$maxLevel = "";
	$level1 = "";
	$level2 = "";
	$level3 = "";
	$level4 = "";
	$level5 = "";
	$level6 = "";
	$level7 = "";
	$level8 = "";
	$level9 = "";
	$level10 = "";
	$level11 = "";
	$level12 = "";
	while($line = mysql_fetch_assoc($results)) {
		 $maxLevel .=$line["MaxLevel"]."\n";
		 $level1 .=$line["Level1"]."\n";
		 $level2 .=$line["Level2"]."\n";
		 $level3 .=$line["Level3"]."\n";
		 $level4 .=$line["Level4"]."\n";
		 $level5 .=$line["Level5"]."\n";
		 $level6 .=$line["Level6"]."\n";
		 $level7 .=$line["Level7"]."\n";
		 $level8 .=$line["Level8"]."\n";
		 $level9 .=$line["Level9"]."\n";
		 $level10 .=$line["Level10"]."\n";
		 $level11 .=$line["Level11"]."\n";
		 $level12 .=$line["Level12"]."\n";


	}
	echo($maxLevel); 
	echo($level1);
	echo($level2);
	echo($level3);
	echo($level4);
	echo($level5);
	echo($level6);
	echo($level7);
	echo($level8);
	echo($level9);
	echo($level10);
	echo($level11);
	echo($level12);
}

//////////GET STARSTAGE2//////////
if($ID=="GET_STARSTAGE2")
{
	$query = "SELECT * FROM starstage2 WHERE User='$_POST[User]'";
	$results = mysql_query($query)or die(mysql_error());

	$maxLevel = "";
	$level1 = "";
	$level2 = "";
	$level3 = "";
	$level4 = "";
	$level5 = "";
	$level6 = "";
	$level7 = "";
	$level8 = "";
	$level9 = "";
	$level10 = "";
	while($line = mysql_fetch_assoc($results)) {
		 $maxLevel .=$line["MaxLevel"]."\n";
		 $level1 .=$line["Level1"]."\n";
		 $level2 .=$line["Level2"]."\n";
		 $level3 .=$line["Level3"]."\n";
		 $level4 .=$line["Level4"]."\n";
		 $level5 .=$line["Level5"]."\n";
		 $level6 .=$line["Level6"]."\n";
		 $level7 .=$line["Level7"]."\n";
		 $level8 .=$line["Level8"]."\n";
		 $level9 .=$line["Level9"]."\n";
		 $level10 .=$line["Level10"]."\n";


	}
	echo($maxLevel); 
	echo($level1);
	echo($level2);
	echo($level3);
	echo($level4);
	echo($level5);
	echo($level6);
	echo($level7);
	echo($level8);
	echo($level9);
	echo($level10);
}

//////////GET UPDATESTAR//////////
if($ID=="GET_UPDATESTAR")
{

	$query = "SELECT * FROM updatestarlevel WHERE User='$_POST[User]'";
	$results = mysql_query($query)or die(mysql_error());

	$skill1 = "";
	$skill2 = "";
	$skill3 = "";
	$skill4 = "";
	$skill5 = "";
	$skill6 = "";
	$totalStar = "";
	while($line = mysql_fetch_assoc($results)) {
		 $skill1 .=$line["Skill1"]."\n";
		 $skill2 .=$line["Skill2"]."\n";
		 $skill3 .=$line["Skill3"]."\n";
		 $skill4 .=$line["Skill4"]."\n";
		 $skill5 .=$line["Skill5"]."\n";
		 $skill6 .=$line["Skill6"]."\n";
		 $totalStar .=$line["TotalStar"]."\n";


	}

	echo($skill1);
	echo($skill2);
	echo($skill3);
	echo($skill4);
	echo($skill5);
	echo($skill6);
	echo($totalStar); 
}

//////////GET TOWER//////////
if($ID=="GET_TOWER")
{
	$query = "SELECT * FROM tower WHERE User='$_POST[User]'";
	$results = mysql_query($query)or die(mysql_error());

	$dataDeso = "";
	$dataRange = "";
	$dataCoint = "";
	$dataDouble = "";
	$dataPercentSell = "";
	$dataCollision = "";

	while($line = mysql_fetch_assoc($results)) {
		 $dataDeso .=$line["Deso"]."\n";
		 $dataRange .=$line["Range"]."\n";
		 $dataCoint .=$line["Coint"]."\n";
		 $dataDouble .= $line["DoubleDamage"]."\n";
		 $dataPercentSell .= $line["PercentSell"]."\n";
		 $dataCollision .=$line["RangeColli"]."\n";



	}

	echo($dataDeso);
	echo($dataRange);
	echo($dataCoint);
	echo($dataDouble);
	echo($dataPercentSell);
	echo($dataCollision);
}

/////////////////////////////////////////SET DATA//////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////SET_SOLIDER//////////
if($ID=="SET_SOLIDER")
{
	$datahp = $_POST['setHp'];
	$datahp1 = $_POST['setHp1'];
	$datahp2 = $_POST['setHp2'];
	$query = "UPDATE solider SET HP =  $datahp, HP1 =$datahp1, HP2 = $datahp2 WHERE User='$_POST[User]'";

	$results = mysql_query($query);
}

//////////SET_SOLIDER_ARMOR//////////
if($ID=="SET_SOLIDER_ARMOR")
{
	$dataArmor = $_POST['setArmor'];
	$dataArmor2 = $_POST['setArmor2'];
	$query = "UPDATE solider SET Armor =  $dataArmor,  Armor2 = $dataArmor2 WHERE User='$_POST[User]'";

	$results = mysql_query($query);
}

//////////SET_SOLIDER_ESPAWN//////////
if($ID=="SET_SOLIDER_ESPAWN")
{
	$query = "UPDATE solider SET Cooldown =  '8', RangeColli = '1.7' WHERE User='$_POST[User]'";
	$results = mysql_query($query);
}

//////////SET_SOLIDER_RESRANGE//////////
if($ID=="SET_SOLIDER_RESRANGE")
{
	$query = "UPDATE solider SET Cooldown =  '8', RangeColli = '1.7' WHERE User='$_POST[User]'";
	$results = mysql_query($query);
}

//////////SET_SOLIDER_MOREHP//////////
if($ID=="SET_SOLIDER_MOREHP")
{
	$datahp = $_POST['setHp'];
	$datahp1 = $_POST['setHp1'];
	$datahp2 = $_POST['setHp2'];
	$query = "UPDATE solider SET HP =  $datahp, HP1 =$datahp1, HP2 = $datahp2 WHERE User='$_POST[User]'";

	$results = mysql_query($query);
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////


//////////SET_ARCHER_PERCENTSELL//////////
if($ID=="SET_ARCHER_PERCENTSELL")
{
	if (isset ($_POST['setPercentSell']))
	{
	   $dataSell = $_POST['setPercentSell'];
	}
	else {
	   $dataSell = '1';
	}

	$query = "UPDATE tower SET PercentSell =  $dataSell WHERE User='$_POST[User]'";

	$results = mysql_query($query);
}

//////////SET_ARCHER_RANGE//////////
if($ID=="SET_ARCHER_RANGE")
{
	if (isset ($_POST['setRange']))
	{
	   $dataRange = $_POST['setRange'];
	}
	else {
	   $dataRange = '1.8';
	}

	$query = "UPDATE tower SET RangeColli =  $dataRange WHERE User='$_POST[User]'";

	$results = mysql_query($query);
}

//////////SET_ARCHER_DESO//////////
if($ID=="SET_ARCHER_DESO")
{
	if (isset ($_POST['setDeso']))
	{
	   $dataDeso = $_POST['setDeso'];
	}
	else {
	   $dataDeso = '10';
	}

	$query = "UPDATE tower SET Deso =  $dataDeso WHERE User='$_POST[User]' ";

	$results = mysql_query($query);
}

//////////SET_ARCHER_MORERANGE //////////
if($ID=="SET_ARCHER_MORERANGE")
{
	if (isset ($_POST['setMoreRange']))
	{
	   $dataRange = $_POST['setMoreRange'];
	}
	else {
	   $dataRange = '1.9';
	}

	$query = "UPDATE tower SET RangeColli =  $dataRange WHERE User='$_POST[User]' ";

	$results = mysql_query($query);
}

//////////SET_ARCHER_DOUBLE//////////
if($ID=="SET_ARCHER_DOUBLE")
{
	if (isset ($_POST['setDouble']))
	{
	   $dataDouble = $_POST['setDouble'];
	}
	else {
	   $dataDouble = '20';
	}

	$query = "UPDATE tower SET DoubleDamage =  $dataDouble WHERE User='$_POST[User]'";

	$results = mysql_query($query);
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////

//////////SET_CANON_DAM//////////
if($ID=="SET_CANON_DAM")
{
	if (isset ($_POST['setMin']))
	{
	   $dataDam = $_POST['setMin'];
	}
	else {
	   $dataDam = '9';
	}
	if (isset ($_POST['setMin1']))
	{
	   $dataDam1 = $_POST['setMin1'];
	}
	else {
	   $dataDam1 = '17';
	}
	if (isset ($_POST['setMin2']))
	{
	   $dataDam2 = $_POST['setMin2'];
	}
	else {
	   $dataDam2 = '33';
	}

	$query = "UPDATE canon SET Mindamage =  $dataDam, Mindamage1 = $dataDam1, Mindamage2 =  $dataDam2 WHERE User='$_POST[User]'";

	$results = mysql_query($query);
}

//////////SET_CANON_COIN//////////
if($ID=="SET_CANON_COIN")
{	
	if (isset ($_POST['setCoin']))
	{
	   $dataCoin= $_POST['setCoin'];
	}
	else {
	   $dataCoin = '90';
	}

	$query = "UPDATE canon SET PercentCoin = $dataCoin WHERE User='$_POST[User]'";

	$results = mysql_query($query);
}

//////////SET_CANON_RANGE//////////
if($ID=="SET_CANON_RANGE")
{
	if (isset ($_POST['setCoin']))
	{
	   $dataCoin= $_POST['setCoin'];
	}
	else {
	   $dataCoin = '1.6';
	}

	$query = "UPDATE canon SET RangeColli = $dataCoin WHERE User='$_POST[User]'";

	$results = mysql_query($query);
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////SET_TOTAL_STAR//////////
if($ID=="SET_TOTAL_STAR")
{
	$query = "UPDATE updatestarlevel SET TotalStar='$_POST[TotalStar]'WHERE User='$_POST[User]'";
	$results = mysql_query($query);

	$results = mysql_query($query);
}
//////////SET_UPDATE_STAR//////////
if($ID=="SET_UPDATE_STAR")
{
	$query = "UPDATE updatestarlevel SET Skill1='$_POST[Skill1]' WHERE User='$_POST[User]'";
	$results = mysql_query($query);

	$query = "UPDATE updatestarlevel SET Skill2='$_POST[Skill2]'WHERE User='$_POST[User]'";
	$results = mysql_query($query);

	$query = "UPDATE updatestarlevel SET Skill3='$_POST[Skill3]'WHERE User='$_POST[User]'";
	$results = mysql_query($query);

	$query = "UPDATE updatestarlevel SET Skill4='$_POST[Skill4]'WHERE User='$_POST[User]'";
	$results = mysql_query($query);

	$query = "UPDATE updatestarlevel SET Skill5='$_POST[Skill5]'WHERE User='$_POST[User]'";
	$results = mysql_query($query);

	$query = "UPDATE updatestarlevel SET Skill6='$_POST[Skill6]'WHERE User='$_POST[User]'";
	$results = mysql_query($query);

	$query = "UPDATE updatestarlevel SET TotalStar='$_POST[TotalStar]'WHERE User='$_POST[User]'";
	$results = mysql_query($query);

	$results = mysql_query($query);
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////

//////////SET_STAGE//////////
if($ID=="SET_STAGE")
{
	$query = "UPDATE stage SET Stage= '$_POST[Stage]' WHERE User='$_POST[User]'";

	$results = mysql_query($query);


	$query = "UPDATE stage SET Question= '$_POST[Question]' WHERE User='$_POST[User]'";

	$results = mysql_query($query);
}

//////////SET_STAR_STAGE_1//////////
if($ID=="SET_STAR_STAGE_1")
{
	$query = "UPDATE starstage1 SET MaxLevel='$_POST[MaxLevel]' WHERE User='$_POST[User]'";
	$results = mysql_query($query);

	$query = "UPDATE starstage1 SET Level1='$_POST[Level1]' WHERE User='$_POST[User]'";
	$results = mysql_query($query);

	$query = "UPDATE starstage1 SET Level2='$_POST[Level2]' WHERE User='$_POST[User]'";
	$results = mysql_query($query);

	$query = "UPDATE starstage1 SET Level3='$_POST[Level3]' WHERE User='$_POST[User]'";
	$results = mysql_query($query);

	$query = "UPDATE starstage1 SET Level4='$_POST[Level4]' WHERE User='$_POST[User]'";
	$results = mysql_query($query);

	$query = "UPDATE starstage1 SET Level5='$_POST[Level5]' WHERE User='$_POST[User]'";
	$results = mysql_query($query);

	$query = "UPDATE starstage1 SET Level6='$_POST[Level6]' WHERE User='$_POST[User]'";
	$results = mysql_query($query);

	$query = "UPDATE starstage1 SET Level7='$_POST[Level7]' WHERE User='$_POST[User]'";
	$results = mysql_query($query);

	$query = "UPDATE starstage1 SET Level8='$_POST[Level8]' WHERE User='$_POST[User]'";
	$results = mysql_query($query);

	$query = "UPDATE starstage1 SET Level9='$_POST[Level9]' WHERE User='$_POST[User]'";
	$results = mysql_query($query);

	$query = "UPDATE starstage1 SET Level10='$_POST[Level10]' WHERE User='$_POST[User]'";
	$results = mysql_query($query);

	$query = "UPDATE starstage1 SET Level11='$_POST[Level11]' WHERE User='$_POST[User]'";
	$results = mysql_query($query);

	$query = "UPDATE starstage1 SET Level12='$_POST[Level12]' WHERE User='$_POST[User]'";
	$results = mysql_query($query);

	$results = mysql_query($query);
}

//////////SET_STAR_STAGE_2//////////
if($ID=="SET_STAR_STAGE_2")
{
	$query = "UPDATE starstage2 SET MaxLevel='$_POST[MaxLevel]' WHERE User='$_POST[User]'";
	$results = mysql_query($query);

	$query = "UPDATE starstage2 SET Level1='$_POST[Level1]' WHERE User='$_POST[User]'";
	$results = mysql_query($query);

	$query = "UPDATE starstage2 SET Level2='$_POST[Level2]' WHERE User='$_POST[User]'";
	$results = mysql_query($query);

	$query = "UPDATE starstage2 SET Level3='$_POST[Level3]' WHERE User='$_POST[User]'";
	$results = mysql_query($query);

	$query = "UPDATE starstage2 SET Level4='$_POST[Level4]' WHERE User='$_POST[User]'";
	$results = mysql_query($query);

	$query = "UPDATE starstage2 SET Level5='$_POST[Level5]' WHERE User='$_POST[User]'";
	$results = mysql_query($query);

	$query = "UPDATE starstage2 SET Level6='$_POST[Level6]' WHERE User='$_POST[User]'";
	$results = mysql_query($query);

	$query = "UPDATE starstage2 SET Level7='$_POST[Level7]' WHERE User='$_POST[User]'";
	$results = mysql_query($query);

	$query = "UPDATE starstage2 SET Level8='$_POST[Level8]' WHERE User='$_POST[User]'";
	$results = mysql_query($query);

	$query = "UPDATE starstage2 SET Level9='$_POST[Level9]' WHERE User='$_POST[User]'";
	$results = mysql_query($query);

	$query = "UPDATE starstage2 SET Level10='$_POST[Level10]' WHERE User='$_POST[User]'";
	$results = mysql_query($query);

	$query = "UPDATE starstage2 SET Level11='$_POST[Level11]' WHERE User='$_POST[User]'";
	$results = mysql_query($query);

	$query = "UPDATE starstage2 SET Level12='$_POST[Level12]' WHERE User='$_POST[User]'";
	$results = mysql_query($query);

	$results = mysql_query($query);
}


mysql_close($link);
}

?>